package com.jason.cloud.engine.share.driver.user.service;

import com.jason.cloud.engine.share.driver.user.bean.UserBean;
import com.jason.cloud.engine.share.driver.user.dao.UserDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Resource
    private UserDao userDao;

    /**
     * 根据ID查询对象
     * @param id
     * @return
     */
    public UserBean queryUserById(String id) {
        UserBean userBean = null;
        try {
            userBean = this.userDao.queryUserById(id);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return userBean;
    }

    /**
     * 保存
     * @param user
     * @return
     */
    public void insertUser(UserBean user) {
        try {
            this.userDao.insertUser(user);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 根据TEL查询对象
     * @param tel
     * @return
     */
    public int existTel(String tel) {
        int count = 0;
        try {
            count = this.userDao.existTel(tel);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return count;
    }

    /**
     * 根据手机号或邮箱登录
     * @param loginName
     * @return
     */
    public UserBean queryUserByLoginName(String loginName) {
        UserBean userBean = null;
        try {
            userBean = this.userDao.queryUserByLoginName(loginName);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return userBean;
    }

    /**
     * 根据EMAIL查询对象
     * @param email
     * @return
     */
    public int existEmail(String email) {
        int count = 0;
        try {
            count = this.userDao.existEmail(email);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return count;
    }

    /**
     * 根据邮箱找回密码
     * @param userBean
     */
    public void forgetPasswordByEmail(UserBean userBean) {
        try {
            this.userDao.forgetPasswordByEmail(userBean);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 列举所有员工
     * @return
     */
    public List<UserBean> getUserLimitByEnterpriseId(int page, int size, String enterpriseId) {
        List<UserBean> userBeanArrayList = new ArrayList<UserBean>();
        try {
            userBeanArrayList = this.userDao.getUserLimitByEnterpriseId(page, size, enterpriseId);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return userBeanArrayList;
    }

    /**
     * 计数员工
     * @return
     */
    public int getUserCountByEnterpriseId(String enterpriseId) {
        int count = 0;
        try {
            count = this.userDao.getUserCountByEnterpriseId(enterpriseId);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return count;
    }

    /**
     * 状态更新
     * @param userBean
     */
    public void updateUserParamById(UserBean userBean) {
        try {
            this.userDao.updateUserParamById(userBean);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }
}
